package m.jclecai.com.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import m.jclecai.com.R;

import java.util.List;

import m.jclecai.com.bean.HomeItem;


/**
 * Created by hp on 2017/3/13.
 */

public class HomeAdapter extends BaseAdapter {

//    public HomeAdapter(Context context, int layoutId, List<HomeItem> datas) {
//        super(context, layoutId, datas);
//    }
//
//    @Override
//    public void onBindViewHolder(RecyclerView.ContinueSignViewHolder holder, int position) {
//
//    }
//
//    @Override
//    protected void convert(ContinueSignViewHolder holder, Object o, int position) {
//        List<HomeItem> list = (List<HomeItem>) o;
//        HomeItem homeItem = (HomeItem) list.get(position);
//        holder.setText(R.id.tv_name, homeItem.getTitle());
//        holder.setImageResource(R.id.iv_icon, homeItem.getIcon());
//        holder.setText(R.id.tv_deplct, homeItem.getDesc());
//    }
    private Context context;
    private List list;
    public HomeAdapter() {

    }

    public HomeAdapter(Context context, List list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = View.inflate(context, R.layout.home_adapter_item, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        HomeItem homeItem = (HomeItem) list.get(position);
        viewHolder.iv_icon.setImageResource(homeItem.getIcon());
        viewHolder.tv_name.setText(homeItem.getTitle());
        viewHolder.tv_deplct.setText(homeItem.getDesc());
        return convertView;
    }

    static class ViewHolder {
        private final ImageView iv_icon;
        private final TextView tv_name;
        private final TextView tv_deplct;

        public ViewHolder(View view) {
            iv_icon = (ImageView) view.findViewById(R.id.iv_icon);
            tv_name = (TextView) view.findViewById(R.id.tv_name);
            tv_deplct = (TextView) view.findViewById(R.id.tv_deplct);
        }
    }
}
